public class work1 {
    //二分查找
    public int takeAttendance(int[] records) {
        int left = 0, right = records.length - 1;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (records[mid] == mid) left = mid + 1;
            else right = mid;
        }
        return left == records[left] ? left + 1 : left;
    }
    public int takeAttendance2(int[] records) {
        int ret1=0,ret2=0;
        for(int i=0;i<records.length;i++){
            ret1+=records[i];
            ret2+=i;
        }
        ret2+=records.length;
        return ret2-ret1;
    }
    //异或^
    public int takeAttendance3(int[] records) {
        int ret=0;
        //a^a=0；自己和自己异或等于0
        // a^0=a；任何数字和0异或还等于他自己
        for(int i=0;i<records.length;i++){
            ret=ret^records[i]^(i+1);
        }
        return ret;
    }
    //暴力解法
    public int takeAttendance4(int[] records) {
        for(int i=0;i<records.length;i++){
            if(i!=records[i])return i;
        }
        return records.length;
    }
}
